<template>
    <div>
        <el-form :model="InboundNumber" ref="PurchaseGoodInbound_ref">
            <el-row>
                <el-col>
                    <el-form-item>
                        <el-table :data="tableData" @selection-change="SelectionChange_event" border>
                            <el-table-column type="selection" width="50" align="center"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="DeviceName" label="名称"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="DeviceModel" label="规格型号"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="Amount" label="采购数量"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="WaitInboundAmount" label="待入库数量"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="InboundAmount" label="入库数量">
                                <template slot-scope="slot">
                                    <el-input v-model="slot.row.InboundAmount" ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="Unit" label="单位"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="ReviewUnitPrice" label="单价"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="TotalPrice" label="总价"></el-table-column>
                            <el-table-column align="center" show-overflow-tooltip prop="ActualPrice" label="实际总价"></el-table-column>
                        </el-table>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>  
                <el-col :span="22" :offset="1"> 
                    <el-form-item label-width="100px" label="备注">
                        <el-input type="texarea" v-model="InboundNumber.Remark"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col align="center">
                    <el-button type="success" @click="Submit_event">确认</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "PurchaseGoodInbound",
        props: {
            tableData: {
                type: Array,
                required: true,
            }
        },
        data() {
            return {
                //表格数据选中项
                SelectMore_lis: [],
                //入库单实体
                InboundNumber: {
                    Remark: '',
                },
            }
        },
        methods: {
            //表单提交,添加采购记录
            Submit_event() {
                if (this.SelectMore_lis.length == 0) {
                    this.$message.warning('请选择入库物资')
                    return
                }
                let result = true
                for (let i = 0; i < this.SelectMore_lis.length; i++) {
                    if (this.SelectMore_lis[i].InboundAmount > this.SelectMore_lis[i].WaitInboundAmount) {
                        this.$message.warning('入库数量不能大于商品剩余数量')
                        result = false
                        return
                    }
                }
                if (result) {
                    let loadding = this.openLoading();
                    this.$http.post('Purchase/AddInboundOrderContent', {
                        InboundOrder: this.InboundNumber,
                        purchaseGoods: this.SelectMore_lis,
                    }).then(res => {
                        loadding.close();
                        if (res.data.IsSuccess) {
                            this.$message.success('入库成功')
                            this.$parent.$parent.formdata()
                            this.formresetField()
                            this.$parent.$parent.PurchaseGoodInbound_dialog = false
                        } else {
                            this.$message.warning('入库失败')
                        }
                    })
                }
            },
            //表格数据选择事件
            SelectionChange_event(value) {
                this.SelectMore_lis = value
            },
            // 表格重置
            formresetField() {
                this.$refs['PurchaseGoodInbound_ref'].resetFields()
            },
        },
    }
</script>

<style scoped>

</style>
